﻿CREATE PROCEDURE state_Repo_AgentsWorkload AS
SET NOCOUNT OFF
EXEC sp__Context_SecurityOff 1
DECLARE @RepoID int,@Agent sysname,@Count int
SELECT TOP 1 @RepoID = ID FROM v_RepoAgents_Active WHERE ISNULL(AgentUserName,'') = '' ORDER BY StatusDate
WHILE @@ROWCOUNT > 0 BEGIN
--[
SELECT TOP 1 @Agent = RAWL.sAMAccountName FROM v_RepoAgentWorkLoad AS RAWL ORDER BY CountWeighted, RAWL.Weight DESC
UPDATE t_Repossession SET AgentUserName = @Agent WHERE ID = @RepoID
SELECT TOP 1 @RepoID = ID FROM v_RepoAgents_Active WHERE ISNULL(AgentUserName,'') = '' ORDER BY StatusDate
--]
END
--SELECT * FROM v_RepoAgentWorkLoad AS RAWL ORDER BY CountWeighted, RAWL.Weight DESC
